/**
 * @param {number[]} code
 * @param {number} k
 * @return {number[]}
 */
var decrypt = function (code, k) {
  let n = code.length
  let newArr = new Array(n).fill(0)
  if (k === 0) return newArr
  if (k > 0) {
    for (let i = 0; i < code.length; i++) {
      for (let j = 1; j <= k; j++) {
        newArr[i] += code[(i + j) % n]
      }
    }
  } else {
    for (let i = 0; i < n; i++) {
      for (let j = 1; j <= Math.abs(k); j++) {
        newArr[i] += code[(i - j + n) % n]
      }
    }
  }

  return newArr
}

console.log(decrypt([10, 5, 7, 7, 3, 2, 10, 3, 6, 9, 1, 6],-4))
